<template>
    <div>
        <el-form ref="form" :model="obj.data" label-width="80px">
            <el-form-item label="名称" prop="name" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.name" clearable autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="市区街道" prop="citys" :rules="[formRulesMixin.notNull]">
                <el-cascader v-model="obj.data.citys" :options="hebeicitys" @change="handleChange" :props="{checkStrictly: true}" style="width:400px;" />
            </el-form-item>
            <el-form-item label="详细地址" prop="address" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.address" clearable autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="负责人" prop="concat" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.concat" clearable autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="联系电话" prop="mobile" :rules="[formRulesMixin.notNull]">
                <el-input v-model="obj.data.mobile" clearable autocomplete="off" maxlength="11" show-word-limit></el-input>
            </el-form-item>

            <el-form-item label="介绍" prop="msg" :rules="[formRulesMixin.notNull]">
                <Editer v-model:value="obj.data.msg" :maxheight="100000" />
            </el-form-item>
            <el-form-item class="dialog-btns-item">
                <div class="dialog-btns">
                    <span class="btn clear" @click="$emit('close')">取消</span>
                    <span class="btn sub ml10" @click.prevent="upData">提交</span>
                </div>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { reactive,getCurrentInstance, ref,computed, toRefs,inject } from 'vue'
    let { proxy } = getCurrentInstance()
    let obj = reactive({
        data:{
            id: inject("id").value || 0,
            name: "",
            citys: ['1301','130110'],
            address: "",
            concat: "",
            mobile:"",
            msg: ""
        },
    });
    let init = () => {
        if(obj.data.id > 0){
            proxy.$ajax({
                url: 'management/get',
                data: obj.data,
                bfLoading: true
            }).then(d => {
                if(d.success){
                    obj.data = {...obj.data, ...d.msg}
                }else{
                    proxy.elMessageMixin(d.err, 'error')
                }
            }).catch(() => { })
        }
    }
    init()
    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                let param = {
                    ...obj.data,
                    city: obj.data.citys[obj.data.citys.length-1]
                }
                console.log(param);
                // return
                proxy.$ajax({
                    url: 'management/design',
                    data: param,
                    bfLoading: true,
                    // timeout:60000
                }).then(d => {
                    console.log(d)
                    if(d.success){
                        proxy.elMessageMixin(`管委会${obj.data.id>0?'修改':"添加"}成功`, 'success')
                        proxy.$emit('init')
                        proxy.$emit('close')
                    }else{
                        proxy.elMessageMixin(d.err, 'error')
                    }
                }).catch(e => { console.log(e) })
            }else{
                return false
            }
        })
    }
</script>

<style scoped>
</style>